package com.demo.controller;

import com.demo.entity.Manager;
import com.demo.entity.base.Result;
import com.demo.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/demo/manager")
public class ManagerController extends BaseController<Manager, ManagerService>{
    private ManagerService managerService;
    @Autowired
   public void setManagerService(ManagerService managerService){
        this.managerService=managerService;
        this.manager=this.managerService;
    }
    @PostMapping("/login")
    public Result login(@RequestBody Manager man) {
        Manager manager = new Manager();
        manager.setUsername(man.getUsername());
        manager.setPassword(man.getPassword());
        int i = managerService.login(manager);
        logger.info(man);
        logger.info(i);
        //0:账户不存在 1:登录成功 2:密码错误
        if (i == 0) return Result.error("账户不存在");
        if (i == 1) return Result.success();
        if (i == 2) return Result.error("密码错误");
        return Result.success();
    }
}
